package day_17.ChengYuanFangFa;

import java.lang.reflect.Method;

public class ReflectDemo1 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException {
        //m1();
        //m2();
        //m3();
        //m4();
        m5();
    }

    private static void m5() throws ClassNotFoundException, NoSuchMethodException {
        //        Method getDeclaredMethod(String name, Class<?>... parameterTypes)：
//                                返回单个成员方法对象
        //1.获取class对象
        Class<?> aClass = Class.forName("day_17.ChengYuanFangFa.Student");
        //2.获取一个成员方法show
        Method method = aClass.getDeclaredMethod("show");
        //3.打印一下
        System.out.println(method);
    }

    private static void m4() throws ClassNotFoundException, NoSuchMethodException {
        //1.获取class对象
        Class<?> aClass = Class.forName("day_17.ChengYuanFangFa.Student");
        //2.获取一个有形参的方法function2
        Method method1 = aClass.getMethod("function2",String.class);
        //3.打印一下
        System.out.println(method1);
    }

    private static void m3() throws ClassNotFoundException, NoSuchMethodException {
        //        Method getMethod(String name, Class<?>... parameterTypes) ：
//                                返回单个公共成员方法对象
        //1.获取class对象
        Class<?> aClass = Class.forName("day_17.ChengYuanFangFa.Student");
        //2.获取成员方法function1
        Method method = aClass.getMethod("function1");
        //3.打印一下
        System.out.println(method);
    }

    private static void m2() throws ClassNotFoundException {
        //        Method[] getDeclaredMethods()：
//                                返回所有成员方法对象的数组，不包括继承的
        //1.获取class对象
        Class aClass = Class.forName("day_17.ChengYuanFangFa.Student");
        //2.获取Method对象
        Method[] declaredMethods = aClass.getDeclaredMethods();
        //3.遍历一下数组
        for (Method declaredMethod : declaredMethods) {
            System.out.println(declaredMethod);
        }
    }

    private static void m1() throws ClassNotFoundException {
        //        Method[] getMethods()：返回所有公共成员方法对象的数组，包括继承的
        //1.获取class对象
        Class<?> aClass = Class.forName("day_17.ChengYuanFangFa.Student");
        //2.获取成员方法对象
        Method[] methods = aClass.getMethods();
        //3.遍历
        for (Method method : methods) {
            System.out.println(method);
        }
    }
}
class lx01{
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException {
        //m1();
        //m2();
        //m3();
        //m4();
        m5();
    }

    private static void m5() throws ClassNotFoundException, NoSuchMethodException {
        Class  aClass = Class.forName("day_17.ChengYuanFangFa.Student");
        Method methods = aClass.getDeclaredMethod("show");
        System.out.println(methods);
    }

    private static void m4() throws ClassNotFoundException, NoSuchMethodException {
        Class  aClass = Class.forName("day_17.ChengYuanFangFa.Student");
        Method method = aClass.getMethod("function2", String.class);
        System.out.println(method);
    }

    private static void m3() throws ClassNotFoundException, NoSuchMethodException {
        Class  aClass = Class.forName("day_17.ChengYuanFangFa.Student");
        Method method = aClass.getMethod("function1");
        System.out.println(method);
    }

    private static void m2() throws ClassNotFoundException {
        Class aClass = Class.forName("day_17.ChengYuanFangFa.Student");
        Method[] declaredMethods = aClass.getDeclaredMethods();
        for (Method declaredMethod : declaredMethods) {
            System.out.println(declaredMethod);
        }
    }

    private static void m1() throws ClassNotFoundException {
        Class aClass = Class.forName("day_17.ChengYuanFangFa.Student");
        Method[] methods = aClass.getMethods();
        for (Method method : methods) {
            System.out.println(method);
        }
    }
}